<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: "billing-config",
});

import { useCrud, useTable, useUpsert, useSearch } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { useI18n } from "vue-i18n";
import { reactive } from "vue";

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	serviceType: [
		{ label: t("短信通知"), value: 0, type: "success" },
		{ label: t("语音通知"), value: 1, type: "warning" },
		{ label: t("物联网卡年费"), value: 2, type: "danger" },
		{ label: t("流量包"), value: 3, type: "info" },
	],
});

// cl-upsert
const Upsert = useUpsert({
	items: [
		{
			label: t("服务类型"),
			prop: "serviceType",
			component: { name: "el-radio-group", options: options.serviceType },
			value: 0,
			required: true,
		},
		// {
		// 	label: t("服务名称"),
		// 	prop: "serviceName",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// 	required: true,
		// },
		{
			label: t("单价"),
			prop: "unitPrice",
			component: { name: "el-input", props: { clearable: true } },
			span: 12,
			required: true,
		},
		// {
		// 	label: t("计费单位"),
		// 	prop: "unit",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// },
		// {
		// 	label: t("是否启用"),
		// 	prop: "isEnabled",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// 	required: true,
		// },
		// {
		// 	label: t("最小计费单位"),
		// 	prop: "minUnit",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// 	required: true,
		// },
		// {
		// 	label: t("描述"),
		// 	prop: "description",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// },
		// {
		// 	label: t("生效时间"),
		// 	prop: "effectiveTime",
		// 	component: {
		// 		name: "el-date-picker",
		// 		props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
		// 	},
		// 	span: 12,
		// },
		// {
		// 	label: t("失效时间"),
		// 	prop: "expireTime",
		// 	component: {
		// 		name: "el-date-picker",
		// 		props: { type: "datetime", valueFormat: "YYYY-MM-DD HH:mm:ss" },
		// 	},
		// 	span: 12,
		// },
		// {
		// 	label: t("排序"),
		// 	prop: "sort",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// 	required: true,
		// },
		// {
		// 	label: t("备注"),
		// 	prop: "remark",
		// 	component: { name: "el-input", props: { clearable: true } },
		// 	span: 12,
		// },
	],
});

// cl-table
const Table = useTable({
	columns: [
		// { type: "selection" },
		{
			label: t("服务类型"),
			prop: "serviceType",
			minWidth: 120,
			dict: options.serviceType,
		},
		// { label: t("服务名称"), prop: "serviceName", minWidth: 120 },
		{ label: t("单价"), prop: "unitPrice", minWidth: 120 },
		// { label: t("计费单位"), prop: "unit", minWidth: 120 },
		// { label: t("是否启用"), prop: "isEnabled", minWidth: 120 },
		// { label: t("最小计费单位"), prop: "minUnit", minWidth: 120 },
		// { label: t("描述"), prop: "description", minWidth: 120 },
		// {
		// 	label: t("生效时间"),
		// 	prop: "effectiveTime",
		// 	minWidth: 170,
		// 	sortable: "custom",
		// 	component: { name: "cl-date-text" },
		// },
		// {
		// 	label: t("失效时间"),
		// 	prop: "expireTime",
		// 	minWidth: 170,
		// 	sortable: "custom",
		// 	component: { name: "cl-date-text" },
		// },
		// { label: t("排序"), prop: "sort", minWidth: 120 },
		// { label: t("备注"), prop: "remark", minWidth: 120 },
		// {
		// 	label: t("创建时间"),
		// 	prop: "createTime",
		// 	minWidth: 170,
		// 	sortable: "desc",
		// 	component: { name: "cl-date-text" },
		// },
		// {
		// 	label: t("更新时间"),
		// 	prop: "updateTime",
		// 	minWidth: 170,
		// 	sortable: "custom",
		// 	component: { name: "cl-date-text" },
		// },
		{ type: "op", buttons: ["edit"] },
	],
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.billing.config,
	},
	(app) => {
		app.refresh();
	},
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
